// 启动 npm nodemon xxx.js  自动运行修改的文件

const person = {
  name: 'joe',
  age: 20,
}

const presonProxy = new Proxy(person, {
  get(target, property) {
    console.log(target, property)
    return target[property] ? target[property] : 'default'
  },
  set(target, property, value) {
    if (property === 'age') {
      if (!Number.isInteger(value)) {
        throw new TypeError(`${value} is not an number`)
      }
    }
    target[property] = value
  },
})

// presonProxy.age = '11111'
// console.log(presonProxy.dfdf)
// console.log(presonProxy.foo)

const list = []

const listProxy = new Proxy(list, {
  set(target, key, value) {
    console.log(target, key, value)
    target[key] = value
    return true //表示设置成功
  },
})

listProxy.push(111)
listProxy.push('joe')
listProxy.push(true)
